TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file HorizBar.php

Documentation is available at HorizBar.php

  1. <?php
  2.  
  3. /**
  4.  * HorizBar Class
  5.  *
  6.  * Description: Horizontal Bar Series
  7.  * bars
  8.  *
  9.  * @author
  10.  * @copyright Copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  11.  * @version 1.0
  12.  * @package TeeChartPHP
  13.  * @subpackage styles
  14.  * @link http://www.steema.com
  15.  */
  16.  
  17.   class HorizBar extends CustomBar {
  18.  
  19.     // Interceptors
  20.     function __get( $property ) {
  21.       $method ="get{$property}";
  22.       if ( method_exists( $this, $method ) ) {
  23.         return $this->$method();
  24.       }
  25.     }
  26.  
  27.     function __set ( $property,$value ) {
  28.       $method ="set{$property}";
  29.       if ( method_exists( $this, $method ) ) {
  30.         return $this->$method($value);
  31.       }
  32.     }
  33.  
  34.     public function HorizBar($c=null) {
  35.         parent::CustomBar($c);
  36.  
  37.         $this->setHorizontal();
  38.         $this->notMandatory->setOrder(ValueListOrder::$ASCENDING);
  39.         $this->mandatory->setOrder(ValueListOrder::$NONE);
  40.         // TODO $tmpGradientDirection = new GradientDirection();
  41.         // TODO $this->getGradient()->setDirection($tmpGradientDirection->HORIZONTAL);
  42.     }
  43.  
  44.         /**
  45.           * Gets descriptive text.
  46.           *
  47.           * @return String 
  48.           */
  49.     public function getDescription() {
  50.         return Language::getString("GalleryHorizBar");
  51.     }
  52.  
  53.         /**
  54.           * Defines the percent of bar Height, from 0 to 100.<br>
  55.           * Default value: 70
  56.           *
  57.           * @return int 
  58.           */
  59.     public function getBarHeightPercent() {
  60.         return $this->barSizePercent;
  61.     }
  62.  
  63.         /**
  64.           * Defines the percent of bar Height, from 0 to 100.<br>
  65.           * Default value: 70
  66.           *
  67.           * @param value int
  68.           */
  69.     public function setBarHeightPercent($value) {
  70.         $this->setBarSizePercent($value);
  71.     }
  72.  
  73.     protected function internalCalcMarkLength($valueIndex) {
  74.         if ($valueIndex == -1) {
  75.             return $this->maxMarkWidth();
  76.         } else {
  77.             return $this->getMarks()->textWidth($valueIndex);
  78.         }
  79.     }
  80.  
  81.     private function otherClicked($p, $tmpX, $endX, $tmpY) {
  82.         if ($this->getBarStyle() == BarStyle::$ELLIPSE) {
  83.             return GraphicsGD::pointInEllipse($p, new Rectangle($tmpX, $tmpY, $endX,
  84.                                              $tmpY + $this->iBarSize));
  85.         } else {
  86.             return ($p->x >= $tmpX) && ($p->x <= $endX);
  87.         }
  88.     }
  89.  
  90.     private function inTriangle($x1, $x2, $tmpY, $p) {
  91.         $this->triP = array();
  92.         $this->iPoints= array();
  93.         $this->triP[0]=new TeePoint();
  94.         $this->triP[1]=new TeePoint();
  95.         $this->triP[2]=new TeePoint();
  96.         $this->triP[3]=new TeePoint();
  97.  
  98.         //$this->Point[] $this->triP = new TeePoint[3];
  99.         $g = $this->chart->getGraphics3D();
  100.         if ($this->chart->getAspect()->getView3D()) {
  101.             $this->triP[0] = $g->calc3DPoint($x1, $tmpY, $this->getStartZ());
  102.             $this->triP[1] = $g->calc3DPoint($x2, $tmpY + ($this->iBarSize / 2), $this->getMiddleZ());
  103.             $this->triP[2] = $g->calc3DPoint($x1, $tmpY + $this->iBarSize, $this->getStartZ());
  104.             return GraphicsGD::pointInPolygon($p, $this->triP);
  105.         } else {
  106.             return GraphicsGD::pointInHorizTriangle($p, $tmpY, $tmpY +
  107.                         $this->iBarSize, $x1, $x2);
  108.         }
  109.     }
  110.  
  111.     protected function internalClicked($valueIndex, $point) {
  112.         $tmpY = $this->calcYPos($valueIndex);
  113.  
  114.         if ((!$this->chart->getAspect()->getView3D()) &&
  115.             (($point->y < $tmpY) || ($point->y > ($tmpY + $this->iBarSize)))) {
  116.             return false;
  117.         }
  118.  
  119.         $tmpX = $this->calcXPos($valueIndex);
  120.         $endX = $this->getOriginPos($valueIndex);
  121.  
  122.         if ($endX < $tmpX) {
  123.             $tmp = $tmpX;
  124.             $tmpX = $endX;
  125.             $endX = $tmp;
  126.         }
  127.  
  128.         $tmpStyle = $this->getBarStyle();
  129.  
  130.         if ($tmpStyle == BarStyle::$INVPYRAMID) {
  131.             return $this->inTriangle($endX, $tmpX, $tmpY, $point);
  132.         } else
  133.         if (($tmpStyle == BarStyle::$PYRAMID) | ($tmpStyle == BarStyle::$CONE)) {
  134.             return $this->inTriangle($tmpX, $endX, $tmpY, $point);
  135.         } else {
  136.             if ($this->chart->getAspect()->getView3D()) {
  137.                  $x = $point->x;
  138.                  $y = $point->y;
  139.                  $p = $this->chart->getGraphics3D()->calculate2DPosition($x, $y,
  140.                         $this->getStartZ());
  141.                 $point->x = $p->x;
  142.                 $point->y = $p->y;
  143.                 if (($point->y >= $tmpY) && ($point->y <= ($tmpY + $this->iBarSize))) {
  144.                     return $this->otherClicked($point, $tmpX, $endX, $tmpY);
  145.                 }
  146.             } else {
  147.                 return $this->otherClicked($point, $tmpX, $endX, $tmpY);
  148.             }
  149.         }
  150.  
  151.         return false;
  152.     }
  153.  
  154.     public function calcHorizMargins($margins) {
  155.         parent::calcHorizMargins($margins);
  156.         $tmp = $this->calcMarkLength( -1);
  157.         if ($tmp > 0) {
  158.             $tmp++;
  159.         }
  160.         if ($this->bUseOrigin && (parent::getMinXValue() < $this->dOrigin)) {
  161.             $margins->min += $tmp;
  162.         }
  163.         if ((!$this->bUseOrigin) || (parent::getMaxXValue() > $this->dOrigin)) {
  164.             if ($this->getHorizAxis()->getInverted()) {
  165.                 $margins->min += $tmp;
  166.             } else {
  167.                 $margins->max += $tmp;
  168.             }
  169.         }
  170.     }
  171.  
  172.     public function calcVerticalMargins($margins) {
  173.         parent::calcVerticalMargins($margins);
  174.         $this->internalApplyBarMargin($margins);
  175.     }
  176.  
  177.         /**
  178.           * Called internally. Draws the "ValueIndex" point of the Series.
  179.           *
  180.           * @param valueIndex int
  181.           */
  182.     public function drawValue($valueIndex) {
  183.         parent::drawValue($valueIndex);
  184.         $this->normalBarColor = $this->getValueColor($valueIndex);
  185.  
  186.          $r = new Rectangle();
  187.  
  188.         if ($this->normalBarColor != Color::EMPTYCOLOR()) {
  189.             $r->y = $this->calcYPos($valueIndex);
  190.         }
  191.  
  192.         if (($this->barSizePercent == 100) && ($valueIndex > 0)) {
  193.             $r->height = $this->calcYPos($valueIndex - 1) - $r->y;
  194.         } else {
  195.             $r->height = $this->iBarSize + 1; // 5.02
  196.         }
  197.  
  198.         $r->x = $this->getOriginPos($valueIndex);
  199.         $r->width = $this->calcXPos($valueIndex) - $r->x;
  200.  
  201.         if (!$this->getPen()->getVisible()) {
  202.             if ($r->getRight() > $r->x) {
  203.                 $r->width++;
  204.             } else {
  205.                 $r->x++;
  206.                 //r.Right--;
  207.             }
  208.             $r->height++; // 5.02
  209.         }
  210.  
  211.         $this->iBarBounds = $r;
  212.  
  213.         if ($r->getRight() > $r->x) {
  214.             $this->drawBar($valueIndex, $r->x, $r->getRight());
  215.         } else {
  216.             $this->drawBar($valueIndex, $r->getRight(), $r->x);
  217.         }
  218.     }
  219.  
  220.     protected function drawMark($valueIndex, $s, $position) {
  221.         $difH = $this->iBarSize / 2;
  222.         $difW = $this->getMarks()->getCallout()->getLength() +
  223.                    $this->getMarks()->getCallout()->getDistance();
  224.         $tmp = ($position->arrowFrom->getX() < $this->getOriginPos($valueIndex));
  225.         if ($tmp) {
  226.             $difW = -$difW - $position->width;
  227.         }
  228.  
  229.         $position->leftTop->setX($position->leftTop->getX() + $difW + ($position->width / 2));
  230.         $position->leftTop->setY($position->leftTop->getY() + $difH + ($position->height / 2));
  231.         $position->arrowTo->setX($position->arrowTo->getX() + $difW);
  232.         $position->arrowTo->setY($position->arrowTo->getY() + $difH);
  233.         $position->arrowFrom->setY($position->arrowFrom->getY() + $difH);
  234.  
  235.         if ($tmp) {
  236.             $position->arrowFrom->setX($position->arrowFrom->getX() - $this->getMarks()->getCallout()->getDistance());
  237.         } else {
  238.             $position->arrowFrom->setX($position->arrowFrom->getX() + $this->getMarks()->getCallout()->getDistance());
  239.         }
  240.  
  241.         parent::drawMark($valueIndex, $s, $position);
  242.     }
  243.  
  244.         /**
  245.           * The pixel Screen Horizontal coordinate of the ValueIndex Series
  246.           * value.<br>
  247.           * This coordinate is calculated using the Series associated Horizontal
  248.           * Axis.
  249.           *
  250.           * @param valueIndex int
  251.           * @return int 
  252.           */
  253.     public function calcXPos($valueIndex) {
  254.         if (($this->iMultiBar == MultiBars::$NONE) || ($this->iMultiBar == MultiBars::$SIDE) ||
  255.             ($this->iMultiBar == MultiBars::$SIDEALL)) {
  256.             return parent::calcXPos($valueIndex);
  257.         } else {
  258.             $tmpValue = $this->vxValues->value[$valueIndex] +
  259.                               $this->pointOrigin($valueIndex, false);
  260.             if (($this->iMultiBar == MultiBars::$STACKED) ||
  261.                 ($this->iMultiBar == MultiBars::$SELFSTACK)) {
  262.                 return $this->calcXPosValue($tmpValue);
  263.             } else {
  264.                 $tmp = $this->pointOrigin($valueIndex, true);
  265.                 return ($tmp != 0) ? $this->calcXPosValue($tmpValue * 100.0 / $tmp) : 0;
  266.             }
  267.         }
  268.     }
  269.  
  270.         /**
  271.           * The vertical Bar position is the "real" Y pos plus the Barwidth by our
  272.           * BarSeries order.<br>
  273.           * This coordinate is calculated using the Series associated Vertical Axis.
  274.           *
  275.           * @param valueIndex int
  276.           * @return int 
  277.           */
  278.     public function calcYPos($valueIndex) {
  279.         (int) $result=0;
  280.  
  281.         if ($this->iMultiBar == MultiBars::$SIDEALL) {
  282.             $result = $this->getVertAxis()->calcYPosValue($this->iPreviousCount + $valueIndex) -
  283.                      ($this->iBarSize / 2);
  284.         } else
  285.         if ($this->iMultiBar == MultiBars::$SELFSTACK) {
  286.             $result = (parent::calcYPosValue($this->getMinYValue())) - ($this->iBarSize / 2);
  287.         } else {
  288.             $result = parent::calcYPos($valueIndex);
  289.             if ($this->iMultiBar != MultiBars::$NONE) {
  290.                 $result += MathUtils::round($this->iBarSize *
  291.                                          ((($this->iNumBars * 0.5) -
  292.                                            (1 + $this->iNumBars - $this->iOrderPos))));
  293.             } else {
  294.                 $result -= ($this->iBarSize / 2);
  295.             }
  296.         }
  297.  
  298.         return $this->applyBarOffset($result);
  299.     }
  300.  
  301.     private function drawBar($barIndex, $startPos, $endPos) {
  302.         $g = $this->chart->getGraphics3D();
  303.  
  304.         $this->setPenBrushBar($this->normalBarColor);
  305.         $r = $this->iBarBounds;
  306.  
  307.         $tmpMidY = ($r->y + $r->getBottom()) / 2;
  308.         $tmp = $this->doGetBarStyle($barIndex);
  309.         if ($this->chart->getAspect()->getView3D()) {
  310.  
  311.             if ($tmp == BarStyle::$RECTANGLE) {
  312.                 $g->cube($startPos, $r->y, $endPos, $r->getBottom(), $this->getStartZ(), $this->getEndZ(),
  313.                        $this->bDark3D);
  314.             } else
  315.             if ($tmp == BarStyle::$PYRAMID) {
  316.                 $g->pyramid(false, $startPos, $r->y, $endPos, $r->getBottom(), $this->getStartZ(),
  317.                           $this->getEndZ(),
  318.                           $this->bDark3D);
  319.             } else
  320.             if ($tmp == BarStyle::$INVPYRAMID) {
  321.                 $g->pyramid(false, $endPos, $r->y, $startPos, $r->getBottom(), $this->getStartZ(),
  322.                           $this->getEndZ(),
  323.                           $this->bDark3D);
  324.             } else
  325.             if ($tmp == BarStyle::$CYLINDER) {
  326.                 $g->cylinder(false, $r, $this->getStartZ(), $this->getEndZ(), $this->bDark3D);
  327.             } else
  328.             if ($tmp == BarStyle::$ELLIPSE) {
  329.                 $g->ellipse($this->iBarBounds, $this->getMiddleZ());
  330.             } else
  331.             if ($tmp == BarStyle::$ARROW) {
  332.                 $g->arrow(true, new TeePoint($startPos, $tmpMidY),
  333.                         new TeePoint($endPos, $tmpMidY),
  334.                         $r->height, $r->height / 2, $this->getMiddleZ());
  335.             } else
  336.             if ($tmp == BarStyle::$RECTGRADIENT) {
  337.                 $g->cube($startPos, $r->y, $endPos, $r->getBottom(), $this->getStartZ(), $this->getEndZ(),
  338.                        $this->bDark3D);
  339.                 if ($g->getSupportsFullRotation() ||
  340.                     $this->chart->getAspect()->getOrthogonal()) {
  341.                     $this->doGradient3D($barIndex,
  342.                                  $g->calc3DPoint($startPos, $r->y, $this->getStartZ()),
  343.                                  $g->calc3DPoint($endPos, $r->getBottom(), $this->getStartZ()));
  344.                 }
  345.             } else
  346.             if ($tmp == BarStyle::$CONE) {
  347.                 $g->cone(false, $this->iBarBounds, $this->getStartZ(), $this->getEndZ(), $this->bDark3D,
  348.                        $this->conePercent);
  349.             }
  350.         } else {
  351.             if (($tmp == BarStyle::$RECTANGLE) |
  352.                 ($tmp == BarStyle::$CYLINDER)) {
  353.                 $this->barRectangle($this->normalBarColor, $this->iBarBounds);
  354.             } else
  355.             if (($tmp == BarStyle::$PYRAMID) |
  356.                 ($tmp == BarStyle::$CONE)) {
  357.                 $this->pCone=array();
  358.                 /*$this->Point[]*/ $this->pCone[0] = new TeePoint($startPos, $r->y);
  359.                     $this->pCone[1] = new TeePoint($endPos, $tmpMidY);
  360.                     $this->pCone[2] = new TeePoint($startPos, $r->getBottom());
  361.                 $g->polygon($this->pCone);
  362.             } else
  363.             if ($tmp == BarStyle::$INVPYRAMID) {
  364.                 $this->pInv=array();
  365.                 /*$this->Point[]*/ $this->pInv[0] = new TeePoint($endPos, $r->y);
  366.                     $this->pInv[0] = new TeePoint($startPos, $tmpMidY);
  367.                     $this->pInv[0] = new TeePoint($endPos, $r->getBottom());
  368.                 $g->polygon($this->pInv);
  369.             } else
  370.             if ($tmp == BarStyle::$ELLIPSE) {
  371.                 $g->ellipse($this->iBarBounds);
  372.             } else
  373.             if ($tmp == BarStyle::$ARROW) {
  374.                 $g->arrow(true, new TeePoint($startPos, $tmpMidY),
  375.                         new TeePoint($endPos, $tmpMidY),
  376.                         $r->height, $r->height / 2, $this->getMiddleZ());
  377.             } else
  378.             if ($tmp == BarStyle::$RECTGRADIENT) {
  379.                 $this->doBarGradient($barIndex,
  380.                               new Rectangle($startPos, $r->y, $endPos - $startPos,
  381.                                             $r->height));
  382.             }
  383.         }
  384.     }
  385.  
  386.     protected function drawSeriesForward($valueIndex) {
  387.         if ($this->iMultiBar == MultiBars::$NONE) {
  388.             return true;
  389.         } else
  390.         if (($this->iMultiBar == MultiBars::$NONE) | ($this->iMultiBar == MultiBars::$SIDEALL)) {
  391.             return false;
  392.         } else
  393.         if (($this->iMultiBar == MultiBars::$STACKED) |
  394.             ($this->iMultiBar == MultiBars::$SELFSTACK)) {
  395.             $result = $this->mandatory->value[$valueIndex] >= 0; /* 5.01 */
  396.             if ($this->getHorizAxis()->getInverted()) {
  397.                 $result = !$result;
  398.             }
  399.             return $result;
  400.         } else {
  401.             return!$this->getHorizAxis()->getInverted();
  402.         }
  403.     }
  404.  
  405.     protected function getOriginPos($valueIndex) {
  406.         return $this->internalGetOriginPos($valueIndex, $this->getHorizAxis()->iStartPos);
  407.     }
  408.  
  409.         /**
  410.           * The Maximum Value of the Series X Values List.
  411.           *
  412.           * @return double 
  413.           */
  414.     public function getMaxXValue() {
  415.         return $this->maxMandatoryValue(parent::getMaxXValue());
  416.     }
  417.  
  418.         /**
  419.           * The Minimum Value of the Series X Values List.
  420.           *
  421.           * @return double 
  422.           */
  423.     public function getMinXValue() {
  424.         return $this->minMandatoryValue(parent::getMinXValue());
  425.     }
  426.  
  427.         /**
  428.           * The Minimum Value of the Series Y Values Lists.<br>
  429.           * As some Series have more than one Y Values List, this Minimum Value is
  430.           * the "Minimum of Minimums" of all Series Y Values lists. <br>
  431.           *
  432.           * @return double 
  433.           */
  434.     public function getMinYValue() {
  435.         if ($this->iMultiBar == MultiBars::$SELFSTACK) {
  436.             return $this->getChart()->getSeriesIndexOf($this);
  437.         } else {
  438.             return parent::getMinYValue();
  439.         }
  440.     }
  441.  
  442.         /**
  443.           * The Maximum Value of the Series Y Values List.
  444.           *
  445.           * @return double 
  446.           */
  447.     public function getMaxYValue() {
  448.         if ($this->iMultiBar == MultiBars::$SELFSTACK) {
  449.             return $this->getMinYValue();
  450.         } else {
  451.             return ($this->iMultiBar == MultiBars::$SIDEALL) ?
  452.                     $this->iPreviousCount + $this->getCount() - 1 :
  453.                     parent::getMaxYValue();
  454.         }
  455.     }
  456. }
  457.  
  458. ?>

Documentation generated on Wed, 16 Jun 2010 12:06:17 +0200 by phpDocumentor 1.4.1